package com.youchuang.action.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.youchuang.action.BaseAction;
import com.youchuang.bean.User;
import com.youchuang.common.Constant;
import com.youchuang.service.AdminService;

import net.sf.json.JSONObject;

/**
 * 会员信息显示
 * 
 * @author Administrator
 *
 */
@Namespace(value = "/admin")
@ParentPackage("shopping-default")
public class UserListAction extends BaseAction {

	private static final Logger logger = Logger.getLogger(UserListAction.class.getSimpleName());
	private JSONObject resultObj;
	
	@Resource
	private AdminService adminService;

	@Action(value = "userList", results = {
			@Result(name = Constant.SUCCESS, type = "json", params = { "root", "resultObj" }) })
	public String execute() throws Exception {
		List<User> users = adminService.findUserByAll();

		Map<String, Object> jsonMap = new HashMap<String, Object>();
		jsonMap.put(Constant.ROWS, users);
		resultObj = JSONObject.fromObject(jsonMap);
		logger.info(resultObj.toString());
		return Constant.SUCCESS;
	}

	public JSONObject getResultObj() {
		return resultObj;
	}

	public void setResultObj(JSONObject resultObj) {
		this.resultObj = resultObj;
	}

}
